package com.sowka.miko.weather;

import java.util.HashMap;
import java.util.Map;

import com.sowka.miko.weather.model.Forecast;
import com.sowka.miko.weather.provider.WeatherProvider;

public class WeatherServiceImpl implements WeatherService {

	private Map<String, WeatherProvider> providers = new HashMap<String, WeatherProvider>();
	private String defaultProviderId;
	
	public WeatherServiceImpl(String defaultProviderId) {
		this.defaultProviderId = defaultProviderId;
	}
	
	@Override
	public void registerProvider(String providerId, WeatherProvider provider) {
		providers.put(providerId, provider);
	}

	@Override
	public void unregisterProvider(String providerId) {
		providers.remove(providerId);
	}

	@Override
	public String[] listProviders() {
		return (String[]) providers.keySet().toArray(new String[providers.size()]);
	}

	@Override
	public Forecast fetchForecast() {
		return fetchForecast(defaultProviderId); 
	}

	@Override
	public Forecast fetchForecast(String providerId) {
		WeatherProvider provider = providers.get(providerId);
		return provider.fetchForecast();
	}

}
